import { Body, Inject, Post } from '@midwayjs/decorator';
import { CoolController, BaseController, CoolUrlTag, TagTypes } from '@cool-midway/core';
import { Validate } from '@midwayjs/validate';
import { RouterService } from '../../service/router/router';
import { CourseService } from '../../service/course';
import { CourseDTO, RemindDTO, UpdateDateDTO } from '../../dto/course';


/**
 * 课表
 */
@CoolUrlTag({ key: TagTypes.IGNORE_TOKEN, value: [] })
@CoolController()
export class CourseController extends BaseController {
    @Inject()
    RouterService: RouterService;

    @Inject()
    courseService: CourseService;

    /**
     * 课表查询
     * @param year 学年
     * @param term 学期
     * @param refresh 是否刷新
     */
    @Post('/course', { summary: '课表查询' })
    @Validate()
    async get_course(@Body() params: CourseDTO) {
        const { year, term, refresh } = params;
        const { success, message, data } = await this.RouterService.get_course(year, term, refresh);
        if (!success) return this.fail(data, message);
        return this.ok(data, message);
    }

    /**
     * 更新日期
     * @param date 日期
     */
    @Post('/updateDate', { summary: '更新日期' })
    @Validate()
    async update_date(@Body() params: UpdateDateDTO) {
        const { date } = params;
        const { success, message, data } = await this.courseService.update_date(date);
        if (!success) return this.fail(data, message);
        return this.ok(data, message);
    }

    /**
    * 课表提醒
    * @param remind 提醒
    */
    @Post('/remind', { summary: '课表提醒' })
    async remind(@Body() params: RemindDTO) {
        const { remind } = params;
        const { success, message, data } = await this.courseService.course_remind(remind);
        if (!success) return this.fail(data, message);
        return this.ok(data, message);
    }
}
